package com.sftz.modules.common.service;

import java.util.List;

import org.nutz.dao.SqlManager;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.sftz.modules.common.dto.CourseScoreSettingDto;
import com.uxuexi.core.common.util.Util;
import com.uxuexi.core.db.dao.IDbDao;
import com.uxuexi.core.db.util.DbSqlUtil;

/**
 * 课程评分设置service
 * <p>
 *
 * @author   朱晓川
 * @Date	 2018年12月11日 	 
 */
@IocBean
public class CourseScoreSettingsService {

	@Inject
	protected IDbDao dbDao;

	@Inject
	protected SqlManager sqlManager;

	/**
	 * 查询课程的评分设置,查询不到则返回null
	 */
	public List<CourseScoreSettingDto> getScoreSettings(Integer courseId) {
		if (!Util.isEmpty(courseId)) {
			Sql settingSql = Sqls.create(sqlManager.get("minapp_common_score_setting"));
			settingSql.setParam("courseId", courseId);
			List<CourseScoreSettingDto> scoreSettings = DbSqlUtil.query(dbDao, CourseScoreSettingDto.class, settingSql);
			return scoreSettings;
		}
		return null;
	}

	/**
	 * 根据作业Id查询,查询不到则返回null
	 */
	public List<CourseScoreSettingDto> getScoreSettingsByHomework(Integer homeworkId) {
		if (!Util.isEmpty(homeworkId)) {
			Sql settingSql = Sqls.create(sqlManager.get("minapp_common_score_settingByHomework"));
			settingSql.setParam("homeworkId", homeworkId);
			List<CourseScoreSettingDto> scoreSettings = DbSqlUtil.query(dbDao, CourseScoreSettingDto.class, settingSql);
			return scoreSettings;
		}
		return null;
	}

	/**
	 * 根据试卷Id查询,查询不到则返回null
	 */
	public List<CourseScoreSettingDto> getScoreSettingsByPaper(Integer paperId) {
		if (!Util.isEmpty(paperId)) {
			Sql settingSql = Sqls.create(sqlManager.get("minapp_common_score_settingByPaper"));
			settingSql.setParam("paperId", paperId);
			List<CourseScoreSettingDto> scoreSettings = DbSqlUtil.query(dbDao, CourseScoreSettingDto.class, settingSql);
			return scoreSettings;
		}
		return null;
	}
}
